<template>
  <div class="aui-card-list">
  <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item :label="$t('genTableTemplate.templateCode')">
          <el-input v-model="dataForm.templateCode" :placeholder="$t('genTableTemplate.templateCode')" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item :label="$t('genTableTemplate.templateName')">
          <el-input v-model="dataForm.templateName" :placeholder="$t('genTableTemplate.templateName')" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item :label="$t('genTableTemplate.appType')">
            <el-select v-model="dataForm.appType" :placeholder="$t('genTableTemplate.appType')" clearable>
              <el-option v-for="template in $getDictList('GEN_TEMP_APP_TYPE', true)" :key="template.val"
                :label="template.label" :value="template.val"></el-option>
            </el-select>
          </el-form-item>
      </el-col>
  </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar setting>
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('gen:genTableTemplate:save')" type="primary" @click="addOrUpdateHandle()">
            {{ $t('add') }}</el-button>
          <el-button v-if="$hasPermission('gen:genTableTemplate:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
          <!-- <el-button icon="el-icon-download" @click="$refs.xTable.openExport()" circle></el-button> -->
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
      <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
        :customs.sync="customColumns" :data="dataList" max-height="auto">
        <vxe-table-column type="checkbox" width="50" align="center"></vxe-table-column>
        <vxe-table-column field="templateCode" show-overflow title="genTableTemplate.templateCode" sortable width="140">
        </vxe-table-column>
        <vxe-table-column field="templateName" show-overflow title="genTableTemplate.templateName"></vxe-table-column>
        <vxe-table-column field="filePath" show-overflow title="genTableTemplate.filePath" width="100">
        </vxe-table-column>
        <vxe-table-column field="fileName" show-overflow title="genTableTemplate.fileName" width="120">
        </vxe-table-column>
        <vxe-table-column field="appType" show-overflow title="genTableTemplate.appType" width="80">
          <template slot-scope="scope">
            {{$getDictLabel('GEN_TEMP_APP_TYPE', scope.row.appType)}}
          </template>
        </vxe-table-column>
        <vxe-table-column field="updater" show-overflow title="common.updater" width="80" align="center">
        </vxe-table-column>
        <vxe-table-column field="updateDate" show-overflow title="common.updateDate" width="140"></vxe-table-column>
        <vxe-table-column title="handle" align="center" width="140">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('gen:genTableTemplate:update')" type="text" icon="el-icon-edit" size="small"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('gen:genTableTemplate:delete')" type="text" icon="el-icon-delete"
              size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      </div>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './genTableTemplate-editTab'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/gen/genTableTemplate/page',
        getDataListIsPage: true,
        deleteURL: '/gen/genTableTemplate',
        deleteIsBatch: true,
        exportURL: '/gen/genTableTemplate/export'
      },
      customColumns: [],
      dataForm: {
        templateCode: '',
        templateName: '',
        appType: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      var title = '编辑代码模板'
      var id
      if (row && row.id) {
        title = '编辑代码模板--' + row.templateName + '(' + row.templateCode + ')'
        id = row.id
      }
      // 打开路由
      var router = {
        name: 'gen-genTableTemplate-editTab',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'gen-genTableTemplate',
        path: 'gen/genTableTemplate-editTab',
        title: title
      }
      var params = {
        id: id,
        timestamp: this.$xeutils.timestamp()
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    }
  }
}
</script>
